package cn.example.web.module.channel.handler;

import cn.example.common.constant.ExampleErrorCode;
import cn.example.web.base.AbstractController;
import cn.example.web.module.user.ParameterConstant;
import cn.example.web.module.user.UserService;
import cn.example.web.module.user.UserVO;
import cn.hutool.core.util.StrUtil;
import org.artifact.core.exception.ArtifactExceptionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestChannelHandler extends AbstractChannelHandler {

	@Autowired
	private UserService userService;
	
	@Override
	protected UserService getUserService() {
		return userService;
	}

	@Override
	protected boolean onCheckLoginParameter(AbstractController controller) {
		return StrUtil.isNotBlank(controller.getPara(ParameterConstant.PASSWORD));
	}
	
	@Override
	protected UserVO onCreate(AbstractController controller, UserVO userVO) {
		String password = controller.getPara(ParameterConstant.PASSWORD);
		userVO.setPassword(password);
		return userVO;
	}

	@Override
	protected UserVO onLogin(AbstractController controller, UserVO userVO) {
		String password = controller.getPara("password");
		ArtifactExceptionUtil.isTrue(ExampleErrorCode.USER_ACCOUNT_PASSWORD_MISMATCH,"账号或密码错误", !userVO.getPassword().equals(password));
		return userVO;
	}

	

}
